package com.woniuxy.meal.controller;


import com.woniuxy.meal.common.Result;
import com.woniuxy.meal.form.SearchStoreInfoForm;
import com.woniuxy.meal.service.StoreInfoService;
import com.woniuxy.meal.service.dto.CategoryDto;
import com.woniuxy.meal.service.dto.StoreInfoDto;
import com.woniuxy.meal.service.dto.WoniuPageDto;
import com.woniuxy.meal.util.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zz
 * @since 2023年06月12日
 */
@RestController
@RequestMapping("/storeInfo")
@Api(tags = "商家信息相关接口")
public class StoreInfoController {

    @Autowired
    private StoreInfoService service;
    @Autowired
    private RedisUtil redisUtil;

    @PostMapping("/search")
    @ApiOperation("Es搜索")
    public Result search(@Valid @RequestBody SearchStoreInfoForm form){
        WoniuPageDto stores =service.searchByEs(form);
        return Result.success(200,"ES搜索商家信息成功",stores);
    }


    @GetMapping("/Info")
    @ApiOperation("展示商家详情页")
    public Result search(Long id) throws Exception {
        StoreInfoDto store = service.getOneStore(id);
        return Result.success(200,"展示商家详情页OK",store);
    }

    @GetMapping("/categories")
    @ApiOperation("获取类别")
    public Result categories(Long storeId) {
        List<CategoryDto> categories = service.getCategories(storeId);
        return Result.success(200,"ok", categories);
    }




}

